package com.koko.config;

import com.koko.properties.RabbitmqProperties;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyRabbitmqConfig {
    @Bean
    public FanoutExchange orderPayReleaseExchange() {
        // 交换机
        return new FanoutExchange(RabbitmqProperties.PAY_SUCCESS_EXCHANGE);
    }

    @Bean
    public Queue payUserQueue() {
        return new Queue(RabbitmqProperties.PAY_SUCCESS_USER_QUEUE);
    }

    @Bean
    public Queue payNotifyQueue() {
        return new Queue(RabbitmqProperties.PAY_SUCCESS_NOTIFY_QUEUE);
    }

    @Bean
    public Queue payCartQueue() {
        return new Queue(RabbitmqProperties.PAY_SUCCESS_CART_QUEUE);
    }

    @Bean
    public Binding orderPayUserBinding(Queue payUserQueue, FanoutExchange orderPayReleaseExchange) {
        return BindingBuilder
                .bind(payUserQueue)
                .to(orderPayReleaseExchange);
    }

    @Bean
    public Binding orderPayNotifyBinding(Queue payNotifyQueue, FanoutExchange orderPayReleaseExchange) {
        return BindingBuilder
                .bind(payNotifyQueue)
                .to(orderPayReleaseExchange);
    }

    @Bean
    public Binding orderPayCartBinding(Queue payCartQueue, FanoutExchange orderPayReleaseExchange) {
        return BindingBuilder
                .bind(payCartQueue)
                .to(orderPayReleaseExchange);
    }
}
